package week5.PP9_2;

public class Gap_Sort {
    public static <T extends Comparable<? super T>> void GapSort(T[] data, int i)
    {
        int position, scan;
        T temp;

        if (i >= data.length)
        {
            System.out.println("间隔过大，无法排序。");
        }
        else {
            for (position = i; position >= 1; position--) {
                for (scan = 0; scan < data.length - position; scan++) {
                    if (data[scan].compareTo(data[scan + position]) > 0)
                            swap(data, scan, scan + position);
                }
            }
        }
    }


    private static <T extends Comparable<? super T>> void swap(T[] data, int index1, int index2)
    {
        T temp = data[index1];
        data[index1] = data[index2];
        data[index2] = temp;
    }
}
